from PyQt4.QtGui import *
from PyQt4.QtCore import *

from gui import Global
import pcIcons

class pcSplashScreen(QSplashScreen):
    def __init__(self):
        QSplashScreen.__init__(self)

        self.message=""
        self.alignment=Qt.AlignLeft
        self.colour=QColor()
        self.rect=QRect()
        self.progress=0

        self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.SplashScreen)

        self.setPixmap(QPixmap(":/splashmask.png"))

        font=QFont("Arial")
        font.setBold(True)
        font.setPixelSize(9)
        font.setStretch(125)
        self.setFont(font)

        self.setMessageRect(QRect(25, 350, 350, 14), Qt.AlignCenter)

    def drawContents(self, painter):
        textPix=self.pixmap()
        painter.setPen(self.colour)
        painter.drawText(self.rect, self.alignment, self.message)

        painter.setBrush(QColor("#FA9397"))
        painter.setPen(QColor("#FA9397"))

        start=25
        end=self.width()-25
        _range=end-start
        _progress=(self.progress/100.0)*_range

        painter.drawRect(25, 325, _progress, 10)

    def showStatusMessage(self, message, colour=Qt.black):
        self.message=message
        self.colour=colour
        self.showMessage(self.message, self.alignment, self.colour)

    def setMessageRect(self, rect, alignment):
        self.rect=rect
        self.alignment=alignment

    def setProgress(self, progress): 
        self.progress=progress
        self.repaint()

class pcButton(QPushButton):
    def __init__(self, text=None, icon=None, layout=None, posX=None, posY=None, parent=None):
        QPushButton.__init__(self, text, parent)

        self.setMinimumHeight(Global.podgable)

        if icon!=None: 
            self.setIcon(icon)
            self.setIconSize(QSize(30,30))

        if layout!=None:
            if None not in (posX, posY): layout.addWidget(self, posX, posY)
            else: layout.addWidget(self)

class pcWidget(QWidget): pass

class pcSpacer(pcWidget):
    def __init__(self, parent=None):
        pcWidget.__init__(self, parent)

        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
